<template>
	<view>
			<view class="product-list">
				<uni-row :gutter="20" style="display: block; width: 100%;">
					<uni-col :span="12" v-for="(item,index) in list" :key="index">
						<view class="product-item" @click="goTo(`../../productDetails/productDetails?id=${item.serviceId}`)">
							<view class="image" v-if="item.image">
								<image :src="listImgUrl + item.image + '?x-image-process=style/style-list'" mode="widthFix"></image>
							</view>
							<view class="image" v-else>
								<image src="https://staticfile-yj.obs.cn-north-4.myhuaweicloud.com/none.png"
									mode="widthFix">
								</image>
							</view>
							<view class="product-con">
								<text class="label">{{item.resume}}</text>
								<view class="title"><text>{{item.title}}</text></view>
								<view><text class="price">¥{{item.price}}</text><text class="see"
										v-if="item.browseNum">{{item.browseNum}}次浏览</text></view>
								<view class="vender">{{item.providerName}}</view>
							</view>
						</view>
					</uni-col>
					
				</uni-row>
				<uni-load-more :status="LoadMore" :content-text="contentText"
					></uni-load-more>
			</view>
	</view>
</template>

<script>
	import {
		baseurl,
		pageFarmProduceCollection
	} from "@/api/user.js";
	let listImgUrl = "https://nongmao.obs.cn-north-4.myhuaweicloud.com/"
	export default {
		data() {
			return {
				nvueWidth: 730,
				list: [],
				page: 1,
				maxpage: 0,
				showLoadMore: false,
				listImgUrl,
				LoadMore: 'noMore',
				contentText: {
					contentdown: '...',
					contentrefresh: '加载中',
					contentnomore: '暂无更多数据'
				},
			}
		},
		onLoad() {
			this.initData();
		},
		onPullDownRefresh() {
			console.log('onPullDownRefresh');
			this.initData();
		},
		onReachBottom() {
			console.log("onReachBottom");
			console.log("page", this.page, this.maxpage)
			if (this.page == this.maxpage) {
				this.LoadMore = 'noMore';
				return
			}
			this.LoadMore = 'loading';
			this.page++;
			this.pageFarmProduceCollection({ //参数
				"condition": null,
				"pageNum": this.page,
				"pageSize": 10
			});
		},
		methods: {
			async pageFarmProduceCollection(options) {
				const res = await pageFarmProduceCollection(options)
				console.log(res);
				this.maxpage = res.returnObj.navigateLastPage;
				this.list = this.list.concat(res.returnObj.list);
				this.LoadMore = 'noMore';
			},
			initData() {
				this.page = 1;
				this.list = [];
				this.LoadMore = "loading";
				this.pageFarmProduceCollection({ //参数
					"condition": null,
					"pageNum": this.page,
					"pageSize": 10
				});
				uni.stopPullDownRefresh();
			},
			goTo(e) {
				var url = e;
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss">
	.product-item{
		flex-flow: row nowrap;
	}
.product-item image{
	width: 276rpx;
	height: 276rpx;
}

.product-con{
	flex: 1;
}
</style>
